<template>
  <div>
    <div class="contaniner">
      <div class="header">
        <!-- 收货信息 -->
        <div class="title">收货地址</div>
        <el-form :model="form" ref="form" :rules="rules" label-width="90px">
          <div class="form" v-show="this.isEdit === false">
            <div class="left">
              <div class="select_box">
                <div style="width: 80px">所在地区：</div>
                <div class="select">
                  <v-distpicker :placeholders="placeholders"></v-distpicker>
                </div>
              </div>
              <!-- <div class="select_box"> -->
              <el-form-item label="详细地址:" prop="area" size="medium ">
                <el-input
                  placeholder="详细地址，街道、门牌号等"
                  style="width: 460px"
                  type="textarea"
                  v-model="form.area"
                ></el-input>
              </el-form-item>
              <!-- </div> -->
              <div class="select_input">
                <el-form-item label="收货人:" prop="user" size="small">
                  <el-input v-model="form.user"></el-input>
                </el-form-item>
                <el-form-item label="联系方式:" prop="phone" size="small">
                  <el-input v-model="form.phone"></el-input>
                </el-form-item>
              </div>
            </div>
            <div class="right">
              <div class="right_box">
                <div><input type="checkbox" />设为默认：</div>
                <div class="btn_Box" style="margin-top: 20px">
                  <div class="btn" @click="handleEdit(true)">保存地址</div>
                  <button class="btn_cancel">取消</button>
                </div>
              </div>
            </div>
          </div>
        </el-form>
        <!-- 切换确认地址 -->
        <div class="area_box" v-show="this.isEdit === true">
          <div class="area">
            <div class="imgbox">
              <img class="areaImg" src="./images/area.png" />
              <div>默认地址:</div>
              <button @click="handleEdit(false)">修改</button>
            </div>
            <div class="text"><i>收货人:</i>{{ form.user }}</div>
            <div class="text"><i>联系方式:</i>{{ form.phone }}</div>
            <div class="text"><i>收货地址</i>:{{ form.area }}</div>
          </div>
          <div class="areaButton">
            <div>地址切换</div>
            <button @click="handleEdit(false)">新建地址</button>
          </div>
        </div>
      </div>
    </div>
    <div class="body">
      <div class="content">
        <div class="text" style="text-align: left">
          下单立返28元余额，余额购物可抵现
        </div>
        <div class="text" style="background-color: #f8f5f0">包裹1</div>
        <div class="text-list">
          <div>商品消息</div>
          <div class="list">
            <div>单价</div>
            <div>数量</div>
            <div>小计</div>
            <div>实付</div>
          </div>
        </div>
        <!-- 商品消息 -->
        <div class="text-num" v-if="!Object.keys(goods).length == 0">
          <div class="Img">
            <img
              style="height: 100px; width: 100px; margin-right: 15px"
              :src="goods.goodDefaultImg"
            />
            <div class="right">
              <div class="name">{{ goods.goodName }}</div>
              <div class="res">{{ goods.goodNum }}</div>
              <div class="totla_text">不支持无忧退货</div>
            </div>
          </div>
          <div class="list">
            <div>￥{{ goods.price }}</div>
            <div>{{ goods.goodNum }}</div>
            <div>￥{{ goods.price * goods.goodNum }}</div>
            <div>￥{{ goods.price * goods.goodNum }}</div>
          </div>
        </div>
        <div class="text-num" v-else>
          <h1 >暂无商品！</h1>
        </div>
        <!-- 结算部分 -->
        <div class="footer">
          <div class="left">
            <div>使用优惠券(0张)<i class="el-icon-question"></i></div>
            <div>兑换优惠券</div>
          </div>
          <div class="list">
            <div class="right">
              <div>使用礼品卡<i class="el-icon-question"></i></div>
              <input type="checkbox" />可用余额 ¥0.00
              <div>添加礼品卡</div>
            </div>
          </div>
        </div>
        <div class="pay">
          <div class="left">
            <div>发票信息<i class="el-icon-question"></i></div>
            <input type="checkbox" />我要开发票
          </div>
          <div class="list">
            <div class="right">
              <div>
                商品合计:<span>¥{{Object.keys(goods).length>0? goods.price * goods.goodNum :0 }}</span>
              </div>
              <div>
                邮费:<i class="el-icon-question"></i><span>¥14.00</span>
              </div>
              <div class="paytotal">
                <div>
                  应付总额:<span>{{Object.keys(goods).length>0? goods.price * goods.goodNum + 14:0 }}</span>
                </div>
                <button @click="toPayhandle(goods.price * goods.goodNum + 14)">
                  去付款
                </button>
              </div>
              <div class="userInfo">
                <div>{{ form.user }}</div>
                <div>{{ form.phone }}</div>
                <div>{{ form.area }}</div>
              </div>
            </div>
          </div>
        </div>
        <div class="checkBox">
          <input type="checkbox" name="" id="" />
          <a href="">同意《网易严选服务协议》</a>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import VDistpicker from "v-distpicker";
export default {
  name: "Pay",
  components: { VDistpicker },
  data() {
    return {
      // 地区选择
      placeholders: {
        province: "请选择 ---",
        city: "--- 请选择 ---",
        area: "--- 请选择 ---",
      },
      // 修改地址切换
      isEdit: false,
      form: {
        user: "",
        phone: "",
        area: "",
      },
      rules: {
        user: [
          { required: true, message: "请输入收货人名称", trigger: "blur" },
        ],
        phone: [{ required: true, message: "请输入电话号码" }],
        area: [{ required: true, message: "请输入收货人地址" }],
      },
      goods: {},
    };
  },
  mounted() {
    const goodsList = JSON.parse(sessionStorage.getItem("goods"));
    if (goodsList) {
      this.goods = goodsList;
    }
  },
  methods: {
    // 保存地址校验
    handleEdit(isEdit) {
      this.$refs.form.validate((valid) => {
        if (valid) {
          this.isEdit = isEdit;
        } else {
          return false;
        }
      });
    },
    // 跳转
    toPayhandle(total) {
      this.$router.push({
        name: "Topay",
        query: {
          total,
        },
      });
    },
  },
};
</script>

<style lang="less" scoped>
.contaniner {
  position: relative;
  padding-top: 40px;
  width: 1090px;
  margin: 0px auto;
  // border: 1px solid greenyellow;
}
.header {
  height: 300px;
  width: 1090px;
  // border: 1px solid rgb(236, 4, 74);
  .title {
    height: 42px;
    font-size: 15px;
    line-height: 42px;
    padding-left: 21px;
    background-color: #f5f5f5;
    color: #9e9a9a;
  }
}
.form {
  width: 1090px;
  box-sizing: border-box;
  height: 280px;
  border: 1px solid #ccc;
  // display: none;
  // margin-bottom: 60px;
  .left {
    padding: 20px;
    width: 600px;
    float: left;
    height: 250px;
    font-size: 14px;
    // border: 1px solid goldenrod;
  }
  .right {
    position: relative;
    margin-top: 35px;
    float: right;
    height: 160px;
    width: 400px;
    border-left: 1px solid #ccc;
    .right_box {
      position: absolute;
      right: 10%;
      top: 30%;
      margin-right: 10px;
      height: 85px;
      width: 300px;
      // border: 1px solid gold;
      .btn_Box {
        display: flex;
        justify-content: space-between;
        .btn {
          text-align: center;
          height: 42px;
          line-height: 42px;
          width: 144px;
          font-size: 16px;
          background-color: #b4a078;
          border: 1px solid #b4a078;
          color: #fff;
          cursor: pointer;
        }
        .btn_cancel {
          margin-left: 10px;
          height: 42px;
          font-size: 16px;
          line-height: 42px;
          width: 144px;
          background-color: #f5f3ef;
          border: 1px solid #b4a078;
          color: #b4a078;
          cursor: pointer;
        }
      }
    }
  }
}
.select_input {
  margin-top: 25px;
  height: 30px;
  width: 610px;
  display: flex;
  align-items: center;
  input {
    border: 1px solid rgba(0, 0, 0, 0.15);
  }
}
.select_box {
  height: 66px;
  width: 610px;
  margin: 15px;
  display: flex;
  justify-content: space-between;
  // border: 1px solid goldenrod;
  .select {
    height: 30px;
    width: 580px;
    display: flex;
    // border: 1px solid greenyellow;
  }
}
.body {
  width: 1090px;
  height: 100%;
  margin: 0px auto;
}
.content {
  width: 1090px;
  margin-top: 20px;
  // height: 720px;
  // overflow: hidden;
  border: 1px solid #ccc;
  .text {
    height: 42px;
    line-height: 42px;
    padding-left: 20px;
    // width: 1070px;
    // border: 1px solid #ccc;
    font-size: 15px;
  }
  .text-list {
    height: 42px;
    line-height: 42px;
    padding-left: 20px;
    width: 1090px;
    box-sizing: border-box;
    border-top: 1px solid #ccc;
    display: flex;
    justify-content: space-between;
    background-color: #f5f5f5;
    color: #999;
    font-size: 15px;
    .list {
      display: flex;
      justify-content: space-around;
      // border: 1px solid gold;
      width: 700px;
      div {
        font-size: 15px;
      }
    }
  }
}
.text-num {
  height: 140px;
  line-height: 42px;
  padding-left: 20px;
  width: 1090px;
  // border: 1px solid #ccc;
  display: flex;
  justify-content: space-between;
  .name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 30px;
  }
  .list {
    display: flex;
    margin-top: 20px;
    font-size: 14px;
    justify-content: space-around;
    // border: 1px solid gold;
    width: 700px;
  }
  .Img {
    width: 358px;
    height: 140px;
    // border: 1px solid paleturquoise;
    display: flex;
    justify-content: space-between;
    .right {
      font-size: 14px;
      width: 280px;
      padding-top: 20px;
      // border: 1px solid gray;
      div {
        height: 25px;
      }
      .totla_text {
        color: red;
      }

      span {
        width: 200px;
        height: 50px;
        border: 1px solid gold;
      }
    }
  }
}
.footer {
  font-size: 14px;
  padding: 20px;
  line-height: 42px;
  padding-left: 20px;
  width: 1090px;
  // border-bottom: 1px solid #ccc;
  display: flex;
  justify-content: space-between;
  background-color: #f5f5f5;
  box-sizing: border-box;
  .left {
    width: 550px;
    border-right: 1px solid #ccc;
  }
  .right {
    position: absolute;
    left: 0px;
    line-height: 30px;
    height: 60px;
    width: 160px;
    // border: 1px solid gold;
  }
  .list {
    position: relative;
    // border: 1px solid #ccc;
    width: 500px;
    div {
      margin-left: 20px;
    }
  }
}
.pay {
  position: relative;
  font-size: 14px;
  height: 300px !important;
  box-sizing: border-box;
  overflow: hidden;
  height: 100%;
  padding: 20px;
  line-height: 42px;
  padding-left: 20px;
  width: 1090px;
  border-top: 1px solid #ccc;
  display: flex;
  justify-content: space-between;
  background-color: #f5f5f5;
  .left {
    height: 80px;
    width: 200px;
    // border: 1px solid gold;
  }
  .right {
    position: absolute;
    right: 0px;
    bottom: 0px;
    line-height: 30px;
    height: 100%;
    width: 300px;
    // border: 1px solid gold;
    .userInfo {
      position: absolute;
      text-align: right;
      right: 50px;
      bottom: 0px;
      width: 200px;
      height: 80px;
      // border: 1px solid green;
    }
    .paytotal {
      margin-top: 15px;
      width: 300px;
      height: 150px;
      border-top: 1px solid rgb(233, 230, 233);
      span {
        color: #d4282d;
        font-size: 21px;
      }
      button {
        // border: 1px solid red;
        border-radius: 3px;
        cursor: pointer;
        margin-left: 23px;
      }
    }
    span {
      position: absolute;
      right: 50px;
    }
    button {
      margin-top: 15px;
      position: absolute;
      left: 20%;
      height: 50px;
      width: 168px;
      line-height: 50px;
      font-size: 16px;
      color: #fff;
      border: 1px solid #b4a078;
      background-color: #b4a078;
    }
  }
  .list {
    position: relative;
    display: flex;
    justify-content: space-around;
    // border: 1px solid rgb(0, 241, 72);
    width: 700px;
  }
}
.checkBox {
  margin-top: 15px;
  float: right;
  // border: 1px solid rgb(235, 11, 67);
  font-size: 14px;
}
.canel_box {
  position: absolute;
  top: 20px;
  width: 1090px;
  height: 300px;
  border: 1px solid #ccc;
  // background-color: blue;
  .btn {
    margin: 150px 500px;
    height: 42px;
    line-height: 42px;
    width: 144px;
    font-size: 16px;
    background-color: #f5f5f5;
    border: 1px solid rgb(168, 167, 167);
    cursor: pointer;
  }
}
.area_box {
  position: absolute;
  top: 80px;
  width: 1090px;
  height: 230px;
  border: 1px solid rgb(225, 231, 230);
  .area {
    margin-top: 20px;
    float: left;
    padding: 30px;
    font-size: 15px;
    width: 300px;
    height: 180px;
    // border: 1px solid red;
    .text {
      padding: 5px 0px;
    }

    i {
      color: #999;
      margin-right: 10px;
    }
    .imgbox {
      display: flex;
      width: 230px;
      line-height: 30px;
      div {
        margin-left: 8px;
      }
      .areaImg {
        height: 30px;
        line-height: 30px;
      }
      button {
        color: #b4a078;
        width: 60px;
        line-height: 30px;
        margin-left: 20px;
        border: 1px solid #b4a078;
        background-color: #f5f3ef;
      }
    }
  }
  .areaButton {
    margin-top: 80px;
    text-align: center;
    float: right;
    width: 250px;
    height: 50px;
    border-left: 1px solid rgb(221, 218, 218);
    div {
      color: #69c;
    }
  }
  button {
    border-radius: 2px;
    width: 96px;
    height: 28px;
    padding: 0;
    letter-spacing: normal;
    line-height: 26px;
    font-size: 12px;
    text-align: center;
    color: #333;
    border: 1px solid #ccc;
    background-color: #f5f5f5;
  }
}
.el-icon-question {
  margin: 0px 10px;
}
.el-form-item {
  margin: 5px 0px;
}
</style>